# output.py
import smtplib
from email.mime.text import MIMEText
from typing import Dict
from classes import Config

def save_to_file(output: str, file_path: str):
    """
    将输出保存到文件。
    :param output: 输出内容。
    :param file_path: 文件路径。
    """
    with open(file_path, 'w') as f:
        f.write(output)

def send_email(output: str, email_config: Dict):
    """
    通过邮件发送输出。
    :param output: 输出内容。
    :param email_config: 邮件配置字典。
    """
    msg = MIMEText(output)
    msg['Subject'] = email_config['subject']
    msg['From'] = email_config['from']
    msg['To'] = email_config['to']

    with smtplib.SMTP(email_config['smtp_server'], email_config['smtp_port']) as server:
        server.login(email_config['username'], email_config['password'])
        server.send_message(msg)

def output_result(output: str, config: Config):
    """
    根据参数选择输出方式。
    :param output: 输出内容。
    :param args: 命令行参数字典。
    """
    
    match config:
        case config.output_file:
            save_to_file(output, config.outputFile)
    
    return output